package lab03.test07;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
 * Created by dell on 2017/12/28.
 */
public class Test07 {
    public static void main(String[] args) {
        String path = "E:\\web.zip";

        File dir = new File("E:\\book\\");
        dir.mkdir();
        ZipInputStream zipInputStream = null;
        FileOutputStream fileOutputStream = null;
        byte[] bytes = new byte[100];
        try {
            try {
                zipInputStream = new ZipInputStream(new FileInputStream(path));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            ZipEntry entry;
            try {
                while((entry = zipInputStream.getNextEntry()) != null){
                    System.out.println(entry.getName());
                    File file = new File(dir,entry.getName());
                    fileOutputStream = new FileOutputStream(file);
                    System.out.println(file.getCanonicalPath());

                    int line;
                    while((line = zipInputStream.read(bytes,0,1)) != -1){

                        String str = new String(bytes,0,line);
                        System.out.print(str);
                        fileOutputStream.write(bytes,0,line);
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }


        } finally {
            try {
                zipInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
